<template>
  <div class="components-container">
    <sweet-modal ref="dialog" class="dialog" :sweetModalMaxWidth="pageWidth" v-bind:blocking="true">
      <h3>{{title}}</h3>
      <div style="margin:10px 20px">
        <div class="layui-form-item" v-if="order === '新增'">
          <div class="layui-inline">
            <label class="layui-form-label">业务编号</label>
            <div class="layui-input-inline">
              <el-input v-model="yhdData.YHDREGNO" placeholder="请输入业务编号" @keyup.enter.native="getRegInfo">
              <el-button slot="append" icon="el-icon-search" @click="getRegInfo"></el-button></el-input>
            </div>
              <el-button type="primary" @click="openRegCheck">选取逝者</el-button>
          </div>
        </div>
        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">逝者姓名</label>
            <div class="layui-input-inline">
              <el-input v-model="yhdData.REGNAME" readonly></el-input>
            </div>
            <label class="layui-form-label">客户姓名</label>
            <div class="layui-input-inline">
              <el-input v-model="yhdData.REGHANDLERNAME"></el-input>
            </div>
            <label class="layui-form-label">备注</label>
            <div class="layui-input-inline">
              <el-input v-model="yhdData.YHDDESC"></el-input>
            </div>
          </div>
        </div>
      </div>
      <div :style="{maxHeight:maxHeight+'px'}" style="overflow:auto;">
        <table class="layui-table" style="border-spacing: 0;">
          <colgroup>
            <col>
            <col width="150">
            <col>
            <col width="120">
            <col>
            <col width="150">
            <col width="80">
          </colgroup>
          <thead>
            <tr>
              <th>缴款人</th>
              <th>缴款方式</th>
              <th>缴款凭证号</th>
              <th>金额</th>
              <th>描述</th>
              <th>经办方</th>
              <th>类型</th>
              <th>操作</th>
            </tr>
          </thead>
          <tbody ref='inputs' id="inputs">
            <tr class="allRow" v-for="(yhl,index) in yhlList">
              <td>
                <el-input @keydown.enter.native="enterEvent(index,0)" v-model="yhl.YHLBUYNAME">
                </el-input>
              </td>
              <td>
                <el-select v-model="yhl.YHLCODNAME" ref="codename" clearable @keydown.enter.native="enterEvent(index,1)">
                  <el-option v-for="item in payment" :key="item.CodeValue" :label="item.CodeName" :value="item.CodeValue">
                  </el-option>
                </el-select>
              </td>
              <td>
                <el-input @keydown.enter.native="enterEvent(index,2)" v-model="yhl.YHLPAYNO">
                </el-input>
              </td>
              <td>
                <el-input @keyup.native="check(index)" @keydown.enter.native="enterEvent(index,3)" v-model="yhl.YHLMOUNT">
                  <template slot="append">元</template>
                </el-input>
              </td>
              <td>
                <el-input @keydown.enter.native="enterEvent(index,4)" v-model="yhl.YHLDESC">
                </el-input>
              </td>
              <td>
                <el-select v-model="yhl.YHLSOURCE" ref="source" clearable @keydown.enter.native="enterEvent(index,5)">
                  <el-option v-for="item in source" :key="item.Value" :label="item.Text" :value="item.Value">
                  </el-option>
                </el-select>
              </td>
              <td>
                <span>{{yhl.YHLTYPEDESC}}</span>
              </td>
              <td>
                <button class="layui-btn layui-btn-small layui-btn-normal" @click="remove(index)" v-if="!yhl.YHLID">
                  <i class="layui-icon">&#xe640;</i>
                </button>
              </td>
            </tr>
          </tbody>
          <tfoot>
            <tr>
              <td colspan="3">合计</td>
              <td>{{ total }}元</td>
              <td></td>
              <td></td>
              <td></td>
              <td>
                <button class="layui-btn layui-btn-small layui-btn-normal" @click="insert()">
                  <i class="layui-icon">&#xe654;</i>
                </button>
              </td>
            </tr>
          </tfoot>
        </table>
      </div>
      <div class="layui-form-item btnCenter sweet-btn">
        <el-button  @click="closeDialog">取消</el-button>
        <el-button type="primary"  @click="submit">提交</el-button>
      </div>
    </sweet-modal>

    <sweet-modal ref="change" class="dialog" :sweetModalMaxWidth="pageWidth" v-bind:blocking="true">
      <h3>{{title}}</h3>
      <div style="margin:10px 20px">
        <div class="layui-form-item" v-if="order === '新增'">
          <div class="layui-inline">
            <label class="layui-form-label">业务编号</label>
            <div class="layui-input-inline">
              <el-input v-model="yhdData.YHDREGNO" placeholder="请输入业务编号" @keyup.enter.native="getRegInfo">
              <el-button slot="append" icon="el-icon-search" @click="getRegInfo"></el-button></el-input>
            </div>
          </div>
        </div>
        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">逝者姓名</label>
            <div class="layui-input-inline">
              <el-input v-model="yhdData.REGNAME" readonly></el-input>
            </div>
            <label class="layui-form-label">客户姓名</label>
            <div class="layui-input-inline">
              <el-input v-model="yhdData.REGHANDLERNAME"></el-input>
            </div>
            <label class="layui-form-label">备注</label>
            <div class="layui-input-inline">
              <el-input v-model="yhdData.YHDDESC"></el-input>
            </div>
          </div>
        </div>
      </div>
      <div :style="{maxHeight:maxHeight+'px'}" style="overflow:auto;">
        <table class="layui-table" style="border-spacing: 0;">
          <colgroup>
            <col>
            <col width="150">
            <col>
            <col width="120">
            <col>
            <col width="150">
            <col width="80">
          </colgroup>
          <thead>
            <tr>
              <th>缴款人</th>
              <th>缴款方式</th>
              <th>缴款凭证号</th>
              <th>金额</th>
              <th>描述</th>
              <th>经办方</th>
              <th>类型</th>
              <th>操作</th>
            </tr>
          </thead>
          <tbody ref='inputs' id="inputs">
            <tr class="allRow">
              <td>
                <el-input @keydown.enter.native="enterEvent(index,0)" v-model="yhdData.REGHANDLERNAME">
                </el-input>
              </td>
              <td>
                <el-select v-model="yhdData.YHDCODNAME" ref="codename" clearable @keydown.enter.native="enterEvent(index,1)">
                  <el-option v-for="item in payment" :key="item.CodeValue" :label="item.CodeName" :value="item.CodeValue">
                  </el-option>
                </el-select>
              </td>
              <td>
                <el-input @keydown.enter.native="enterEvent(index,2)" v-model="yhdData.YHDPAYNO">
                </el-input>
              </td>
              <td>
                <el-input @keyup.native="check(index)" @keydown.enter.native="enterEvent(index,3)" v-model="yhdData.YHDSYMOUNT">
                  <template slot="append">元</template>
                </el-input>
              </td>
              <td>
                <el-input @keydown.enter.native="enterEvent(index,4)" v-model="yhdData.YHLDESC">
                </el-input>
              </td>
              <td>
                <el-select v-model="yhdData.YHDSOURCE" ref="source" clearable @keydown.enter.native="enterEvent(index,5)">
                  <el-option v-for="item in source" :key="item.Value" :label="item.Text" :value="item.Value">
                  </el-option>
                </el-select>
              </td>
              <td>
                <!-- {{yhdData.YHLTYPEDESC}} -->
                <span>退款</span>
              </td>
              <td>
                <button class="layui-btn layui-btn-small layui-btn-normal" @click="remove(index)" v-if="!yhl.YHLID">
                  <i class="layui-icon">&#xe640;</i>
                </button>
              </td>
            </tr>
          </tbody>
          <tfoot>
            <tr>
              <td colspan="3">合计</td>
              <td>{{ totals }}元</td>
              <td></td>
              <td></td>
              <td></td>
              <td>
                <button class="layui-btn layui-btn-small layui-btn-normal" @click="insert()">
                  <i class="layui-icon">&#xe654;</i>
                </button>
              </td>
            </tr>
          </tfoot>
        </table>
      </div>
      <div class="layui-form-item btnCenter sweet-btn">
        <el-button  @click="closeDialog">取消</el-button>
        <el-button type="primary"  @click="submit">提交</el-button>
      </div>
    </sweet-modal>

    <sweet-modal ref="info" class="dialog" :sweetModalMaxWidth="pageWidth" v-bind:blocking="true">
      <h3>{{title}}</h3>
      <div style="margin:10px 20px">
        <div class="layui-form-item" v-if="order === '新增'">
          <div class="layui-inline">
            <label class="layui-form-label">业务编号</label>
            <div class="layui-input-inline">
              <el-input v-model="yhdData.YHDREGNO" placeholder="请输入业务编号" @keyup.enter.native="getRegInfo">
              <el-button slot="append" icon="el-icon-search" @click="getRegInfo"></el-button>
              </el-input>
            </div>
          </div>
        </div>
        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">逝者姓名</label>
            <div class="layui-input-inline">
              <el-input v-model="yhdData.REGNAME" readonly></el-input>
            </div>
            <label class="layui-form-label">客户姓名</label>
            <div class="layui-input-inline">
              <el-input v-model="yhdData.REGHANDLERNAME"></el-input>
            </div>
            <label class="layui-form-label">备注</label>
            <div class="layui-input-inline">
              <el-input v-model="yhdData.YHDDESC"></el-input>
            </div>
          </div>
        </div>
      </div>
      <div :style="{maxHeight:maxHeight+'px'}" style="overflow:auto;">
        <table class="layui-table" style="border-spacing: 0;">
          <colgroup>
            <col>
            <col width="150">
            <col>
            <col width="120">
            <col>
            <col width="150">
            <col width="80">
          </colgroup>
          <thead>
            <tr>
              <th>缴款人</th>
              <th>缴款方式</th>
              <th>缴款凭证号</th>
              <th>金额</th>
              <th>描述</th>
              <th>经办方</th>
              <th>类型</th>
            </tr>
          </thead>
          <tbody ref='inputs'>
            <tr class="allRow" v-for="(yhl,index) in yhlList" @click="choosetr(yhl,index)">
              <td>
                {{ yhl.YHLBUYNAME }}
              </td>
              <td>
                {{yhl.YHLCODNAME}}
              </td>
              <td>
                {{ yhl.YHLPAYNO }}
              </td>
              <td>
                <span v-if="yhl.YHLTYPE==='C'">-</span>{{ yhl.YHLMOUNT }}元
              </td>
              <td>
                {{ yhl.YHLDESC }}
              </td>
              <td>
                {{yhl.YHLSOURCEDESC}}
              </td>
              <td>
                <span>{{yhl.YHLTYPEDESC}}</span>
              </td>
            </tr>
          </tbody>
          <tfoot>
            <tr>
              <td colspan="3">合计</td>
              <td>{{ total }}元</td>
              <td></td>
              <td></td>
              <td></td>
            </tr>
          </tfoot>
        </table>
      </div>
      <div class="layui-form-item btnCenter sweet-btn">
        <el-button @click="closeDialog">取消</el-button>
        <el-button @click="printsfqd" v-if="order === '详情'">打印押金收费清单</el-button>
        <el-button @click="charge" v-if="order === '收费'">收费</el-button>
      </div>
    </sweet-modal>
    <sweet-modal ref="dialogPrint" class="dialog" :sweetModalMaxWidth="pageWidth">
        <h3>{{titles}}</h3>
        <iframe :src="printUrl" style="width:1000px; height:500px;margin-top:20px;"></iframe>
    </sweet-modal>
     <!-- 逝者选择 -->
    <sweet-modal ref="deadSelect" class="dialog">
      <h3>逝者选择</h3>
      <div class="layui-form-item">
        <label class="layui-form-label">到馆时间</label>
        <div class="layui-input-inline">
          <el-date-picker v-date v-model="regCheckDate" @change="getRegData" type="date" placeholder="选择日期时间">
          </el-date-picker>
        </div>
      </div>
      <div style="height:400px;max-height:400px;overflow:auto;">
        <table class="layui-table">
          <thead>
            <tr>
              <th>业务编号</th>
              <th>逝者姓名</th>
              <th>联系人</th>
              <th>死亡日期</th>
              <th>操作</th>
            </tr>
          </thead>
          <tbody>
            <tr v-for="item in regCheckList">
              <td>{{item.REGBUSNUM}}</td>
              <td>{{item.REGNAME}}</td>
              <td>{{item.REGHANDLERNAME}}</td>
              <td>{{item.REGDEATHDATE}}</td>
              <td>
                <button @click="getDead(item)" class="layui-btn layui-btn-normal">选择</button>
              </td>
            </tr>
          </tbody>
        </table>
      </div>
    </sweet-modal>
  </div>
</template>

<style rel="stylesheet/scss" lang="scss" scoped>
@import "src/styles/common.scss";
.el-button + .el-button {
  margin-left: 0;
}
.longtext {
  width: 480px;
}
.longertext {
  width: 770px;
}
.sweet-btn {
  margin-top: 20px;
}

</style>
<script>
import apiBase from "@/api/apiBase.js";
import { ORDER } from "@/const/orderConst.js";
import sweetModal from "@/components/sweetModal";
import { accAdd, Subtr } from "@/utils/operations.js";
import { formatDate, timeStringToDate } from "@/utils/date.js";
export default {
  name: "deposit",
  data() {
    return {
      double: null,
      title: null,
      titles: null,
      printUrl: null,
      order: null,
      YHLIDS: null,
      totals: null,
      pageWidth: 1100,
      maxHeight: 500,
      YHDID: null,
      payment: [],
      source: [],
      yhdData: {
        YHDREGNO: null,
        YHDREGID: null,
        REGNAME: null,
        REGHANDLERNAME: null,
        YHDDESC: null,
        YHDCODNAME: null,
      },
      yhlList: [],
      yhl: {
        YHLID: null,
        YHLBUYNAME: null,
        YHLCODNAME: "现金",  // 上虞默认值
        YHLPAYNO: null,
        YHLMOUNT: 0,
        YHLDESC: null,
        YHLSOURCE: null
      },
       regCheckDate: null, //(逝者选取日期)
       regCheckList: null, //逝者选取数据
       IsTakeRegOrPrp: null,
    };
  },
  methods: {
      //打开逝者选取 （上虞）
        openRegCheck() {
            this.regCheckDate = new Date();
            this.getRegData();
            this.$refs.deadSelect.open();
        },
        //获取火化登记数据
        getRegData() {
            let data = {
                Data: {
                    RegdateEquals: formatDate(this.regCheckDate, "yyyyMMdd")
                }
            };
            apiBase.DoService(
                data,
                apiBase.getApiAdress().Registration.QueryAllRegistration,
                res => {
                    this.regCheckList = res.data.content.OutData;
                }
            );
        },
        //选择
        getDead(item) {
            this.yhdData.YHDREGNO = item.REGBUSNUM;
            this.getRegInfo()
            this.$refs.deadSelect.close();
        },
    //获取付款方式
    getPayment() {
      let data = {};
      apiBase.DoService(data, apiBase.getApiAdress().Code.GetPayment, res => {
        this.payment = res.data.content;
        this.yhdData.YHDCODNAME = "现金";
      });
    },
    //获取经办方
    getSource() {
      let data = {};
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Deposit.GetYhlSource,
        res => {
          this.source = res.data.content;
        }
      );
    },
    //根据正式业务编号获取ID
    getRegInfo() {
      let data = {
        REGNO: this.yhdData.YHDREGNO
      };
            if(this.IsTakeRegOrPrp){
                  apiBase.DoService(
                      data,
                      apiBase.getApiAdress().Registration.GetRegOrPrpByNo,
                      res => {
                      let reg = res.data.content;  
                         if(!reg)
                        {
                          this.$message({
                          type: "error",
                          message: "未找到逝者信息!"
                          });
                          Object.assign(
                            this.$data.yhdData,
                            this.$options.data().yhdData
                            );
                          return;
                        }
                      this.yhdData.YHDREGID = reg.REGID;
                      this.yhdData.REGNAME = reg.REGNAME;
                      this.yhdData.REGHANDLERNAME = reg.REGHANDLERNAME;
                      this.yhdData.YHDDESC = reg.REGREMARK;
                      this.yhlList[0].YHLBUYNAME = this.yhdData.REGHANDLERNAME;  //上虞缴款人默认值
                      }
                  );
                }else{
                  apiBase.DoService(
                    data,
                    apiBase.getApiAdress().Registration.GetRegistrationByNo,
                    res => {
                      let reg = res.data.content;
                      if(!reg)
                        {
                          this.$message({
                          type: "error",
                          message: "未找到逝者信息!"
                          });
                          Object.assign(
                            this.$data.yhdData,
                            this.$options.data().yhdData
                            );
                          return;
                        }
                      this.yhdData.YHDREGID = reg.REGID;
                      this.yhdData.REGNAME = reg.REGNAME;
                      this.yhdData.REGHANDLERNAME = reg.REGHANDLERNAME;
                      this.yhdData.YHDDESC = reg.REGREMARK;
                    }
                  );
              }
            },
    //新增押金
    dataAdd() {
      if(this.double === false) return false;
      this.double = false;
      let yhlList = JSON.parse(JSON.stringify(this.yhlList));
      yhlList = yhlList.filter(item => {
        return item.YHLCODNAME && item.YHLCODNAME.length > 0;
      });
      let data = JSON.parse(JSON.stringify(this.yhdData));
      if (yhlList.length > 0) {
        data.list_Yhl = yhlList;
      }else{
        this.$message({
          type: "error",
          message: "缴款方式不能为空!"
        });
        return;
      }
      apiBase.DoService(data, apiBase.getApiAdress().Deposit.Create, res => {
        this.$message({
          type: "success",
          message: "保存成功!"
        });
        this.closeDialog();
        this.refreshData();
      },
      res =>{
        this.double = true;
        this.$message.error(res.data.msg);
      });
    },
    //修改押金
    dataModify() {
      if(this.double === false) return false;
      this.double = false;
      let yhlList = JSON.parse(JSON.stringify(this.yhlList));
      yhlList = yhlList.filter(item => {
        return item.YHLCODNAME && item.YHLCODNAME.length > 0;
      });
      let data = JSON.parse(JSON.stringify(this.yhdData));
      if (yhlList.length > 0) {
        data.list_Yhl = yhlList;
      }
      apiBase.DoService(data, apiBase.getApiAdress().Deposit.Modify, res => {
        this.$message({
          type: "success",
          message: "保存成功!"
        });
        this.closeDialog();
        this.refreshData();
      },
      res =>{
        this.double = true;
        this.$message.error(res.data.msg);
      });
    },
    //退款
    refund() {
      if(this.double === false) return false;
      this.double = false;
      // let yhlList = JSON.parse(JSON.stringify(this.yhlList));
      // yhlList = yhlList.filter(item => {
      //   return item.YHLCODNAME && item.YHLCODNAME.length > 0;
      // });
      let data = JSON.parse(JSON.stringify(this.yhdData));
      data.list_Yhl = [
        {YHLBUYNAME: data.REGHANDLERNAME,YHLCODNAME: data.YHDCODNAME,YHLTYPEDESC: '退款',YHLPAYNO: data.YHDPAYNO,YHLDESC: data.YHLDESC,YHLSOURCE: data.YHDSOURCE,YHLTYPE: "C",YHLMOUNT: data.YHDSYMOUNT}
      ];
      // if (yhlList.length > 0) {
      //   data.list_Yhl = yhlList;
      // }
      // data.list_Yhl[0].YHLBUYNAME = data.REGHANDLERNAME;
      // data.list_Yhl[0].YHLCODNAME = data.YHDCODNAME;
      // data.list_Yhl[0].YHLTYPEDESC = '退款';
      // data.list_Yhl[0].YHLPAYNO = data.YHDPAYNO;
      // data.list_Yhl[0].YHLDESC = data.YHDDESC;
      // data.list_Yhl[0].YHLSOURCE = data.YHDSOURCE;
      // data.list_Yhl[0].YHLTYPE = "C";
      // data.list_Yhl[0].YHLMOUNT = data.YHDSYMOUNT;
      // data.list_Yhl[0].YHLID = this.YHLIDS;
      // for(var i = 0;i < this.source.length;i++){
      //   if(this.source[i].Value == data.YHDSOURCE){
      //     data.list_Yhl[0].YHLSOURCEDESC = this.source[i].Text;
      //   }
      // }
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Deposit.DepositRefund,
        res => {
          this.$message({
            type: "success",
            message: "保存成功!"
          });
          this.closeDialog();
          this.refreshData();
        },
        res =>{
        this.double = true;
        this.$message.error(res.data.msg);
      });
    },
    //押金详情
    dataInfo() {
      let data = {
        YHDID: this.YHDID
      };
      apiBase.DoService(data, apiBase.getApiAdress().Deposit.Detail, res => {
        this.yhdData = res.data.content;
        this.yhdData.YHDREGID = this.yhdData.REGID;
        this.totals = this.yhdData.YHDSYMOUNT;
        if (this.order !== ORDER.REFUND) {
          this.yhlList = this.yhdData.list_Yhl;
          this.YHLIDS = this.yhlList[0].YHLID
        }
        if (this.order !== ORDER.INFO&&this.order !== ORDER.MODIFY) {
          this.insert();
        }
      });
    },
    //新增行
    insert() {
      for (let index in this.yhlList) {
        let yhl = this.yhlList[index];
        if (yhl.YHLCODNAME.length === 0) {
          this.$message({
            type: "error",
            message: `第${parseInt(index) + 1}行缴款方式不能为空!`
          });
          return false;
        }
        if (yhl.YHLMOUNT.length === 0) {
          this.$message({
            type: "error",
            message: `第${parseInt(index) + 1}行金额不能为空!`
          });
          return false;
        }
      }
      if (this.order === ORDER.ADD || this.order === ORDER.MODIFY) {
        this.yhl.YHLTYPEDESC = "缴款";
      } else if (this.order === ORDER.REFUND) {
        this.yhl.YHLTYPEDESC = "退款";
      } else {
        this.yhl.YHLTYPEDESC = "";
      }
      this.yhl.YHLBUYNAME = this.yhdData.REGHANDLERNAME;   // 上虞每一行缴款人 默认值
      this.yhlList.push(JSON.parse(JSON.stringify(this.yhl)));
      return true;
    },
    remove(index) {
      this.yhlList.splice(index, 1);
    },
    //回车事件
    enterEvent(rowNum, colNum) {
      //获取所有行
      // let rows = this.$refs.inputs.getElementsByClassName("allRow");
      let rows = document.getElementById('inputs');
      //获取当前行
      // let currow = rows[rowNum];
      let currow = rows.getElementsByTagName('tr')[rowNum];  
      // 获取当前行所有列
      let inputs = currow.getElementsByTagName("input");
      //强制隐藏下拉框
      if (colNum === 1 || colNum === 5) {
        let codename = this.$refs.codename;
        codename[rowNum].visible = false;
        let source = this.$refs.source;
        source[rowNum].visible = false;
      }
      //最后一列
      if (colNum === inputs.length - 1) {
        //最后一行
        if (rowNum === this.yhlList.length - 1) {
          //插入空行
          if (!this.insert()) {
            return;
          }
        }
        //换行
        this.$nextTick(function() {
          this.enterEvent(rowNum + 1, -1);
        });
      } else {
        //获取下一个焦点
        this.$nextTick(function() {
          inputs[colNum + 1].select();
        });
      }
    },
    //打开页面
    open(order, id) {
      this.YHDID = id;
      this.order = order;
      //清理数据
      this.dataRepeat();
      this.getPayment();
      this.getSource();
      this.double = true;
      switch (this.order) {
        case ORDER.ADD:
          this.title = "押金新增";
          this.yhl.YHLBUYNAME=this.yhdData.REGHANDLERNAME
          this.insert();
          this.$refs.dialog.open();
          break;
        case ORDER.CHARGE:
          this.title = "收费";
          this.dataInfo();
          this.$refs.info.open();
          break;
        case ORDER.MODIFY:
          this.title = "押金修改";
          this.dataInfo();
          this.$refs.dialog.open();
          break;
        case ORDER.REFUND:
          this.title = "押金退款";
          this.dataInfo();
          this.$refs.change.open();
          break;
        case ORDER.INFO:
          this.title = "押金详情";
          this.dataInfo();
          this.$refs.info.open();
          break;
        default:
      }
    },
    //提交
    submit() {
      switch (this.order) {
        case ORDER.ADD:
          this.dataAdd();
          break;
        case ORDER.MODIFY:
          this.dataModify();
          break;
        case ORDER.REFUND:
          this.refund();
          break;
        default:
      }
    },
    //收费
    charge(){
      let data = {
          YHDID: this.YHDID
         };
            apiBase.DoService(
               data,
               apiBase.getApiAdress().Deposit.Cash,
               res => {
                this.$message({
                  type: "success",
                  message: "收费成功!"
                });
                this.closeDialog();
                this.refreshData();
               }
             );
    },
    //选中行
    choosetr(val,index){
      this.YHLIDS = val.YHLID;
       //获取所有行
      let rows = this.$refs.inputs.getElementsByClassName("allRow");
      for(var i = 0;i < rows.length;i++){
        rows[i].style.backgroundColor = "#fff";
      }
      //获取当前行
      let currow = rows[index];
      currow.style.backgroundColor = '#f2f2f2';
    },
    //打印押金收费清单
    printsfqd(){
      let data = {
        YHLID: this.YHLIDS
      };
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Pdf.PrintDepositlist,
        res => {
          this.titles = '打印押金票据';
          this.printUrl = res.data.content.PDFNAME;
          this.$refs.dialogPrint.open();
        }
      );
    },
    closeDialog() {
      this.$refs.dialog.close();
      this.$refs.info.close();
      this.$refs.change.close();
    },
    refreshData() {
      this.$emit("refreshData");
    },
    check(index) {
      let yhl = this.yhlList[index];
      yhl.YHLMOUNT = this.checkMoney(yhl.YHLMOUNT.toString());
    },
    //只能输入金额
    checkMoney(value) {
      //修复第一个字符是小数点 的情况.
      if (value !== "" && value.substr(0, 1) === ".") {
        value = "";
      }
      value = value.replace(/^0*(0\.|[1-9])/, "$1"); //解决 粘贴不生效
      value = value.replace(/[^\d.]/g, ""); //清除“数字”和“.”以外的字符
      value = value.replace(/\.{2,}/g, "."); //只保留第一个. 清除多余的
      value = value
        .replace(".", "$#$")
        .replace(/\./g, "")
        .replace("$#$", ".");
      value = value.replace(/^(\-)*(\d+)\.(\d\d).*$/, "$1$2.$3"); //只能输入两个小数
      if (value.indexOf(".") < 0 && value !== "") {
        //以上已经过滤，此处控制的是如果没有小数点，首位不能为类似于 01、02的金额
        if (value.substr(0, 1) === "0" && value.length === 2) {
          value = value.substr(1, value.length);
        }
      } else if (value === "") {
        value = 0;
      }
      return value;
    },
    //数据重置
    dataRepeat() {
      this.yhlList = [];
      Object.assign(this.$data.yhdData, this.$options.data().yhdData);
    }
  },
  computed: {
    total() {
      let total = 0;
      for (let yhl of this.yhlList) {
        if (this.order === ORDER.MODIFY || this.order === ORDER.INFO) {
          if (yhl.YHLTYPE === "A") {
            total = accAdd(total, yhl.YHLMOUNT);
          } else if (yhl.YHLTYPE === "C") {
            total = Subtr(total, yhl.YHLMOUNT);
          }
        } else {
          total = accAdd(total, yhl.YHLMOUNT);
        }
      }
      return total;
    }
  },
  components: {
    sweetModal
  },
     created(){
      // 礼厅开始使用是否取预约火化信息(嵊州)
      apiBase.DoService(
          {},
          apiBase.getApiAdress().Param.GetIsTakeRegOrPrp,
          res => {
              this.IsTakeRegOrPrp = res.data.content;
          }
      );
     }
};
</script>

